﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPixmap>
#include<QFrame>
#include<QHBoxLayout>
#include<QFileDialog>
#include<QString>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Init();
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::Init()
{
    //设置主界面背景
    this->setGeometry(400,40,1400,1000);
   // QPixmap pixmap(":/image/background.jpg");//设定图片
    QPalette palette;//创建一个调色板对象
    //palette.setBrush(backgroundRole(),QBrush(pixmap));//用调色板的画笔把映射到pixmap上的图片画到frame.backgroundRole()这个背景上
    //setPalette(palette);//设置窗口调色板为palette，窗口和画笔相关联
   // setAutoFillBackground(true);//设置窗体自动填充背景
    this->setWindowTitle(QString::fromLocal8Bit("视频播放器"));
    this->setWindowIcon(QIcon(":/image/icon.png"));//设置窗体图标


    //头部
    QPixmap *pixmap = new QPixmap(":/image/headerbg.png");
    pixmap->scaled(ui->label->size(), Qt::KeepAspectRatio);
    ui->label->setScaledContents(true);
    ui->label->setPixmap(*pixmap);
    //按钮
    ui->pushButton->setGeometry(0,0,175,100);
    ui->pushButton_2->setAutoFillBackground(true);
    ui->pushButton_3->setAutoFillBackground(true);
    ui->pushButton_4->setAutoFillBackground(true);
    ui->pushButton_5->setAutoFillBackground(true);

    ui->pushButton_2->setGeometry(0,101,175,100);
    ui->pushButton_3->setGeometry(0,202,175,100);
    ui->pushButton_4->setGeometry(0,303,175,100);
    ui->pushButton_5->setGeometry(0,404,175,100);

    page1 = new Page1(this);
    page2 = new Page2(this);
    page3 = new Page3(this);
    page4 = new Page4(this);
    page5 = new Page5(this);

    ui->stackedWidget->addWidget(page1);
    ui->stackedWidget->addWidget(page2);
    ui->stackedWidget->addWidget(page3);
    ui->stackedWidget->addWidget(page4);
    ui->stackedWidget->addWidget(page5);
    ui->stackedWidget->setCurrentWidget(page2);

    QObject::connect(page2,SIGNAL(sendNewStr(QString)),this,SLOT(setStateBar(QString)));
    QObject::connect(page3,SIGNAL(sendNewStr(QString)),this,SLOT(setStateBar(QString)));
    QObject::connect(page4,SIGNAL(sendNewStr(QString)),this,SLOT(setStateBar(QString)));
    QObject::connect(page2,SIGNAL(sendVideoPath(QString)),this,SLOT(setVideoPath(QString)));
    QObject::connect(this,SIGNAL(sendVideoPath(QString)),page3,SLOT(getVideoPath(QString)));
    QObject::connect(page2,SIGNAL(sendVideoTime(qint64)),page3,SLOT(getVideoTime(qint64)));
 }


void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(page2);
    ui->pushButton->setStyleSheet("color:white");
    ui->pushButton->setStyleSheet("background-color:#2CA7F8");
    this->repaint();
}

void MainWindow::on_pushButton_2_clicked()
{
    ui->stackedWidget->setCurrentWidget(page1);
}

void MainWindow::on_pushButton_3_clicked()
{
    ui->stackedWidget->setCurrentWidget(page3);
}
void MainWindow::on_pushButton_4_clicked()
{
    ui->stackedWidget->setCurrentWidget(page4);
}

void MainWindow::on_pushButton_5_clicked()
{
     ui->stackedWidget->setCurrentWidget(page5);
}

void MainWindow::setStateBar(QString str)
{
    ui->textEdit->append(str);
}
void MainWindow::setVideoPath(QString str)
{
    videoPath=str.toUtf8().data();
    emit sendVideoPath(str);
}
